Individual-based models

Let's start with a simple model of the size of population of organisms. We'll ignore sex (so, suppose these are hermaphroditic).

Population growth

Each year, each individual will

  1. maybe reproduce, and then
  2. maybe die.

To make a model we need to decide exactly how those steps happen. How about:

  1. Each individual produces a random, Poisson number of offspring, with mean $\lambda$, and then
  2. survives with probability $p$ (or else, dies).
  3. Every individual does this independently of everyone else.

Population regulation

Those populations grew exponentially, if they didn't die out. What if we want a stable population? Let's say that there's "room" for around $K$ individuals, total, and so that each new individual finds "space" to live with probability $1 - N/K$ when there's $N$ adults present. So,

  1. Each individual produces a random, Poisson number of offspring, with mean $\lambda$, and then
  2. each adult survives with probability $p$ (or else, dies), while
  3. each new offspring survives with probability $1-N/K$, if there are $N$ individuals currently.
  4. Every individual does this independently of everything else.

This is (a stochastic version of) the logistic model of population growth, with fecundity/recruitment/juvenile mortality regulation.

Exercise: explore parameter space

How do the three parameters, $\lambda$, $p$, and $K$, affect the dynamics? For instance: the stable population size? the rate of growth when small? Try to explain what and why.

Math: it works

Now we'll see how our math-based predictions match the "reality" of our simulations.

Speeding this up with probability

But first, let's speed up the code a bit, so we can simulate larger populations.

Above we did sum(np.random.uniform(0, 1, N) < p) to find the number of survivors: all N individuals flip p-coins to decide if they live or not. Why, that's just the Binomial($N$, $p$) distribution! So, we could have just done np.random.binomial(N, p, 1).

Also, we did sum(np.random.poisson(lam, N)). But, what about additivity of Poissons? If $X_1, \ldots, X_n$ are all Poisson random variables, with means $\lambda_1, \ldots, \lambda_n$ respectively, then $X_1 + \cdots X_n$ is also Poisson, with mean $\lambda_1 + \cdots + \lambda_n$. That means we could have done np.random.poisson(N * lam, 1) instead.

Finally, we will be producing a Poisson number of offspring, then each one flips a coin to decide whether to survive. By the Poisson thinning property, the resulting random number is again Poisson distributed. In other words, if $N$ is Poisson($\lambda$) and $M$ is Binomial($N$, $q$) given $N$, then $M$ is Poisson($\lambda q$).

We'll also vectorize this, to do many simulations at once.

It's equation time

What we're seeing can be thought of as a combination of two things: a deterministic trend, with randomness on top. To describe this, we will work out the mean and variance of the population size at the next time step, as a function of the current population size: $$\begin{aligned} \mathbb{E}[N_{t+1} | N_t = n] &= F(n) \\ \text{Var}[N_{t+1} | N_t = n] &= V(n) . \end{aligned}$$

Suppose that the current population size is $N_t = n$. Given this, what's the mean and variance of $N_{t+1}$? Well, if $S$ is the number of survivors, and $T$ is the number of offspring, then $N_{t+1} = S + T$, and $$\begin{aligned} T &\sim \text{Poisson}(\lambda n (1-n/K)) \\ S &\sim \text{Binomial}(n, p) . \end{aligned}$$ (The distribution for $T$ follows from the additivity and thinning properties of the Poisson distribution, above.) These have mean and variance $$\begin{aligned} \mathbb{E}[T] = \text{Var}[T] = \lambda n (1-n/K) \\ \mathbb{E}[S] = np \qquad \text{Var}[S] = np(1-p) . \end{aligned}$$

Putting this together, we have that $$\begin{aligned} F(n) &= n \left( p + \lambda \left(1 - \frac{n}{K}\right)\right) \\ &= n + n \left( p + \lambda - 1 - \frac{\lambda n}{K}\right) \\ V(n) &= n \left( p (1-p) + \lambda \left(1 - \frac{n}{K}\right) \right) \\ &= F(n) - n p^2 . \end{aligned}$$

The equilibrium

If $F(n_*) = n_*$, then the expected size of a population in the next generation that starts with $n_*$ individuals is unchanged. If not for randomness, a population starting with $n_*$ individuals would stay at that size forever. To find if such a population size exists, and if so, what it is, we solve $$ F(n_*) - n_* = n_* \left( p + \lambda - 1 - \frac{\lambda n_*}{K} \right) = 0 . $$ This has two solutions, zero and $n_* = K (\lambda + p - 1)/\lambda$. If this second solution is positive, then there's a positive equilibrium value.

Time to generalize

And, to save on typing, here's code to "record a bunch of simulations in the columns of an array".

Lots of simulations

Ok, finally let's run the simulations, now with our theoretically predicted equilibrium size on top.

Noise?

Notice above that the variance of the next time step is proportional to the the number of deaths plus the number of births. This means the standard deviation is proportional to the square root of this. Suppose that in a population of size $N$ there are $R$ births plus deaths. This means that roughly a proportion $R/2N$ of the population is getting replaced each time step. At the next time step, we expect the population to be of size $F(N)$ plus or minus some "noise" of size $\sqrt{R}$. Since $R$ can't be much bigger than $N$, $\sqrt{R}/N$, the size of the noise relative to the population, is of order $1/\sqrt{N}$.

This means that we expect the step-to-step contribution of noise to be smaller in bigger populations.

We can see that in the plot above: the population is roughly of size $N=100$, and the fluctuations about the average are of order 10.

Homework 1

The Ricker model replaces $1 - N/K$ with $\exp(-N/K)$. How similar is it? Simulate from it, solve for the equilibrium value, and check your answer with simulations.

Logistic cobwebs

Now let's look more at the function $n \mapsto F(n)$. We can do this the "math-free" way by just plotting the population size after one time step of the simulation starting from a grid of possible initial sizes. The diagonal red line is where $F(n) = n$, i.e.: equilibrium!

That's hard to see! Let's look at $n \mapsto (F(n) - n)$ instead. The horizontal line is where $F(n) - n = 0$, again: equilibrium!

New parameters

Now let's spice things up by changing the parameters to $$\begin{aligned} \lambda &= 5 \\ p &= 0.25 \\ K &= 200 \end{aligned}$$

Wow, what happened? The population is oscillating. Let's look at $F(n)$ to understand.

Question: What's that wierd tail?

The cobweb plot

Using a plot of the expected value curve $f(n) = \mathbb{E}[N_{t+1} | N_t = n]$, you can trace the expected dynamics as $$ n \mapsto f(n) \mapsto f(f(n)) \mapsto f(f(f(n))) \mapsto \cdots $$ by "bouncing off the diagonal".

It's easier to explain with a picture.

Exercise: dizzy spiders

Fact: If the slope of $F()$ (the blue curve above) at the equilibrium (the magenta dotted lines) is steeper than $-1$, then the equilibrium is unstable (and so the population will tend to oscillate around it).

Experiment to convince yourself of this, draw pictures on the whiteboard with your neighbor, then explain why this happens.

What about noise?

Above we saw that bigger populations had less noise (in this model anyhow). This says that bigger populations should behave more like solutions to the differential equation. Let's see how that holds up in our simulations.

Oscillations, and Chaos

It would be a crime to talk about the logistic equation and not see period doubling, and chaos. A nice review of complicated behavior in simple models is May 1976. In this section we'll just work with the determinstic model (remember that $r = \lambda + p -1$ and we'll switch out $K$ for $n_* = K r / \lambda$, to be consistent with the literature).

To see if the model approaches a stable, oscillating equilibrium, we can (a) iterate the model for a while, and then see if the values repeat. For instance, at $r=2.1$ there's a period-2 loop:

Here's another example (at $r=2.5$, with period 4):

... and, what's going on here???

Ok, now let's see how that behaves as we change $r$. To save space, we'll (a) cut out the first bunch of steps of each simulation, and (b) plot the values of $N_t$ against their respective values of $r$ (so the first plot above would be compressed to just two points, at about 82 and 111, above $r=2.1$.

The first "period doubling", where the single stable cycle becomes unstable, occurs at $r=\sqrt{6}$. The period doubles again, followed soon by the onset of chaos.

Homework 2

Here is another "logistic" model. Suppose that everyone dies every time step, and that large populations deplete the amount of resources left for the next generation. The net effect is that the mean fecundity of an individual in a population of size $N$ is $1 + r - N/\beta$, so that $1+r$ is the mean fecundity in the presence of lots of resources, but that mean fecundity decreases by $1/\beta$ for each additional neighbor. Implement a simulation of this process (using Poisson offspring and Poisson additivity), and plot how it evolves. Write down and solve the equations to find its equilibrium in terms of $r$ and $\beta$.

Bonus: We can't see chaos in our simulations above because of the max(0.0, 1-N/K) term. We can see it in this model. Find parameter values with (a) a bistable cycle and (b) chaos.